<script setup lang="ts">
import { ref ,onMounted} from 'vue';
// import { areaList } from '@vant/area-data';

const showSheet = ref(false) // 显示面板
const showSelectBirthday = ref(false) // 显示选择生日
const showSelectProfesstion = ref(false) // 显示职业
const showSelectCity = ref(false) // 显示城市
const minDate = new Date("1980-01-01")
const maxDate = new Date("2010-01-01")
// 显示面板的数据
const actions = [
    { name: '拍照上传' },
    { name: '从相册选择' },
];

const areaList = ref<CityAreaList>()
onMounted(() => {
    areaList.value = hdm.getAreaList() // 获取这个数据
})

// 职业的数据
const columns = [
    { text: '软件工程师', value: '软件工程师' },
    { text: '医生', value: '医生' },
    { text: '教师', value: '教师' },
    { text: '律师', value: '律师' },
    { text: '会计师', value: '会计师' },
    { text: '销售经理', value: '销售经理' },
    { text: '市场营销专员', value: '市场营销专员' },
    { text: '建筑师', value: '建筑师' },
    { text: '护士', value: '护士' },
    { text: '机械工程师', value: '机械工程师' }
]

</script>

<template>
  <div class="profile-edit-page">
    <!-- 头像部分 -->
    <div class="avatar">
      <van-image
      @click="showSheet = true"
        round
        width="100"
        height="100"
        class="avatar-img"
        src="https://foruda.gitee.com/avatar/1716533299289369832/5539886_yjh8866_1716533299.png"
      >
      </van-image>
      <div @click="showSheet = true"  class="avatar-btn">
        <span>修改头像</span>
      </div>
    </div>

    <!-- 中间表单部分 -->
    <van-cell-group>
      <van-field label="账号" readonly></van-field>
      <van-field label="昵称" placeholder="请输入昵称"></van-field>
      <van-cell title="性别" class="gender">
        <van-radio-group :icon-size="16">
          <van-radio name="男">男</van-radio>
          <van-radio name="女">女</van-radio>
          <van-radio name="未知">未知</van-radio>
        </van-radio-group>
      </van-cell>
      <van-field label="生日" readonly placeholder="请选择日期" @click="showSelectBirthday = true" ></van-field>
      <van-field label="所在地" readonly placeholder="请选择所在地" @click="showSelectCity = true" ></van-field>
      <van-field label="职业" readonly placeholder="请选择职业" @click="showSelectProfesstion = true" ></van-field>
    </van-cell-group>

    <div class="submit">
      <van-button round block type="primary"> 保存资料 </van-button>
    </div>

    <van-action-sheet v-model:show="showSheet" :actions="actions" cancel-text="取消" close-on-click-action />
 <!-- 选择生日弹层 -->
    <van-popup v-model:show="showSelectBirthday" position="bottom">
            <van-date-picker @confirm="showSelectBirthday = false" @cancel="showSelectBirthday = false" title="选择日期"
                :min-date="minDate" :max-date="maxDate" />
        </van-popup>
      <!-- 选择职业弹层 -->
      <van-popup v-model:show="showSelectProfesstion" position="bottom">
            <!-- 职业picker -->
            <van-picker title="选择职业" :columns="columns" @confirm="showSelectProfesstion = false"
                @cancel="showSelectProfesstion = false" />
        </van-popup>
        <!--选择城市-->
        <van-popup v-model:show="showSelectCity" position="bottom">
             <!-- 城市选择 -->
             <van-area :area-list="areaList" title="选择城市" @confirm="showSelectCity = false"
                @cancel="showSelectCity = false"></van-area>
        </van-popup>

 </div>
 
</template>

<style lang="css" scoped>
.avatar {
  padding: 30px;
  text-align: center;
  background-color: var(--mk-white);
}

.avatar-img {
  box-shadow: 0 0 5px var(--mk-gray);
}

.avatar-btn {
  color: var(--mk-linear_end);
  margin-top: 10px;
}

/* ::v-deep 通过深度选择器修改组件库的样式 */
.gender ::v-deep(.van-cell__title) {
  width: 100px;
  flex: none;
}

.van-radio-group {
  display: flex;
  justify-content: space-between;
  height: 36px;
  width: 180px;
}

.submit {
  padding: 16px;
}
</style>
